﻿namespace KingerRobot.MexicoSailunMDC.SpiService;

internal interface IWmsOutOrderSummary
{
    List<SummaryInCuringCount> GetTaskSummaryOccupyCount();
    List<POWmsOutOrderSummary> GetOccupySummarys();

    /// <summary>
    /// 异常任务修改数量
    /// </summary>
    /// <param name="summaryId">明细表ID</param>
    /// <returns></returns>
    int UpdateOutOrderSumaryRealNum(long summaryId);
    /// <summary>
    /// 更新订单的库存数
    /// </summary>
    /// <param name="summaryId">明细表ID</param>
    /// <returns></returns>
    int UpdateOutOrderSumaryInventory(long summaryId, int inventory, int crnInventory, long crnId, long taskId);
    /// <summary>
    /// 修改完成数量
    /// </summary>
    /// <param name="summaryId"></param>
    /// <returns></returns>
    int UpdateOutOrderSumaryTargetNum(long summaryId, int count = 1);
    /// <summary>
    /// 修改备注
    /// </summary>
    /// <param name="summaryIds"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int UpdateOrderSummaryRemark(List<long> summaryIds, string remark, bool isAppend = false);

    /// <summary>
    /// 修改订单明细的masterId
    /// </summary>
    /// <param name="summaryId"></param>
    /// <param name="masterId"></param>
    /// <returns></returns>
    int UpdateOrderSummaryMasterId(long summaryId, long masterId, long newmasterId);
    /// <summary>
    /// 物料是否相同
    /// </summary>
    /// <returns></returns>
    bool IsMateiralSameSummary(List<long?> ids);
    /// <summary>
    /// 获取出库单信息
    /// </summary>
    /// <param name="type">类型</param>
    /// <param name="status">状态</param>
    /// <returns></returns>
    List<POWmsOutOrderSummary> GetOutOrderSummaryList(int type, int status);
    /// <summary>
    /// 
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    List<OrderSummaryGroupyMaster> GetNoTaskLocOrderSummaryGroup(int type);
    /// <summary>
    /// 未创建请料任务的出库订单(所有类型【硫化请料、普通出库、库位出库】)
    /// </summary>
    /// <returns></returns>
    public List<POWmsOutOrderSummary> GetOutOrderSummaryNoTaskList(int?[] type);

    List<POWmsOutOrderSummary> GetOutOrderSummaryHasTaskList();

    /// <summary>
    /// 未创建任务的请料单，汇总 Master 获取 Summary
    /// </summary>
    /// <param name="type">出库订单类型</param>
    /// <returns></returns>
    List<OrderSummaryGroupyMaster> GetNoTaskOrderSummaryGroup(int type);
    /// <summary>
    /// 创建任务后修改出库订单
    /// </summary>
    /// <param name="Id"></param>
    /// <param name="StartLoc"></param>
    /// <param name="Count"></param>
    /// <returns></returns>
    int UpdateSummaryLocAndRealCount(long? id, long? startLoc, int count = 0, string remark = "");
    /// <summary>
    ///  回滚数量修改
    /// </summary>
    /// <param name="id"></param>
    /// <param name="remark"></param>
    /// <param name="count"></param>
    /// <returns></returns>
    int RollBackSummaryLocAndRealCount(long? id, string remark, int count = 0);
    /// <summary>
    /// 修改完成方式
    /// </summary>
    /// <param name="masterId"></param>
    /// <returns></returns>
    int UpdateOutOrderSummaryAllFinish(long masterId, int finishMode);

    /// <summary>
    /// 修改完成
    /// </summary>
    /// <param name="summaryId"></param>
    /// <param name="finishMode"></param>
    /// <returns></returns>
    int UpdateOutOrderSummaryFinish(long summaryId, int finishMode);


    /// <summary>
    /// 添加出库订单信息
    /// </summary>
    /// <param name="outOrderSummaries"></param>
    /// <returns></returns>
    int AddOutOrderSummaryList(List<OutOrderSummary> outOrderSummaries);
    /// <summary>
    /// 根据库位出库
    /// </summary>
    /// <param name="WmsOutOrderSummaries">订单明细</param>
    /// <returns></returns>
    int AddOutOrderSummaryListByLoc(List<POWmsOutOrderSummary> WmsOutOrderSummaries);
    /// <summary>
    /// 通过货位ID获取订单信息
    /// </summary>
    /// <param name="locId"></param>
    /// <returns></returns>
    POWmsOutOrderSummary GetOutOrderSummaryByTargetLocId(long locId);
    /// <summary>
    /// 通过开始位置查找订单
    /// </summary>
    /// <param name="locId"></param>
    /// <returns></returns>
    POWmsOutOrderSummary GetOutOrderSummaryByStartLocId(long locId);
    /// <summary>
    /// 批量查询
    /// </summary>
    /// <param name="locIds"></param>
    /// <returns></returns>
    List<POWmsOutOrderSummary> GetOutOrderSummarysByTargetLocId(long locId);
    /// <summary>
    /// 通过货位ID判断是否已经请料
    /// </summary>
    /// <param name="equipId"></param>
    /// <returns></returns>
    bool IsOutOrderSummaryByLocId(long locId);
    /// <summary>
    /// 是否配对（true 配对；false 不配对）
    /// </summary>
    /// <param name="locId"></param>
    /// <returns></returns>
    bool IsOutOrderSummaryPairByLocId(long locId);
    /// <summary>
    /// 获取出库单信息
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    POWmsOutOrderSummary GetOutOrderSummaryById(long id);
    /// <summary>
    /// 获取直运订单
    /// </summary>
    /// <param name="locId"></param>
    /// <returns></returns>
    POWmsOutOrderSummary GetDirectDeliveryOutOrderSummary(long locId, long materialId);
    /// <summary>
    /// 获取出库单信息
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    List<POWmsOutOrderSummary> GetOutOrderSummaryByMasterId(long masterId);
    /// <summary>
    /// 通过物料获取未生成任务订单
    /// </summary>
    /// <param name="materialId"></param>
    /// <returns></returns>
    List<POWmsOutOrderSummary> GetOutOrderSummaryNoTaskByMaterialId(long materialId);
    /// <summary>
    /// 获取出库订单是否还有明细数据
    /// </summary>
    /// <param name="masterId"></param>
    /// <returns></returns>
    bool IsOutOrderSummaryByMasterId(long masterId);

    /// <summary>
    /// 重新请料从表
    /// </summary>
    /// <param name="summaryId"></param>
    /// <returns></returns>
    int ReRequestSummary(long summaryId);

    /// <summary>
    /// 备份删除订单从表
    /// </summary>
    /// <param name="id"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int BakUpdateAndDeleteOutOrderSummary(POWmsOutOrderSummary summary, string remark = "");
    /// <summary>
    /// 备份并删除订单信息
    /// </summary>
    /// <param name="masterId"></param>
    /// <returns></returns>
    int BakAndDeleteOutOrderSummary(long id);
    /// <summary>
    /// 通过主表id删除从表
    /// </summary>
    /// <param name="masterId"></param>
    /// <returns></returns>
    int BakAndDeleteOutOrderSummaryByMasterId(long masterId, string remark);
    /// <summary>
    /// 验证硫化线体任务数量是否允许继续出库
    /// </summary>
    /// <param name="loc">目标硫化机所在库位</param>
    /// <returns></returns>
    bool GetOutOrderSummaryDitchCount(long loc);

    /// <summary>
    /// 硫化排请料任务数【true 未超，继续执行；false 超限，停止执行】
    /// </summary>
    /// <param name="loc"></param>
    /// <returns></returns>
    bool IsCuringDitchTaskCount(long loc);
    /// <summary>
    /// 安全信号修改
    /// </summary>
    /// <param name="targetLoc"></param>
    /// <param name="safe"></param>
    /// <returns></returns>
    int UpdateOutOrderSumarySafe(long targetLoc, int safe);

    /// <summary>
    /// 通过ids获取出库单从表信息
    /// </summary>
    /// <param name="ids"></param>
    /// <returns></returns>
    List<POWmsOutOrderSummary> GetOutOrderSummaryByIds(List<long?> ids);

    /// <summary>
    /// 获取备份出库单信息
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    POBakWmsOutOrderSummary GetBakOutOrderSummaryById(long id);

    /// <summary>
    /// 通过TcmNo 判断左右膜是否有未生成任务的当前物料的请料单 如果
    /// </summary>
    /// <param name="TcmNo"></param>
    /// <returns></returns>
    int UpdateSummaryByTcmNoAndSpec(string TcmNo,string Spec);
}


public class OrderSummaryGroupyMaster
{
    /// <summary>
    /// 订单主ID
    /// </summary>
    public long MasterId { get; set; }
    /// <summary>
    /// 订单明细数量
    /// </summary>
    public int Count { get; set; }
    /// <summary>
    /// 订单创建时间
    /// </summary>
    public DateTime? CreateTime { get; set; }
    /// <summary>
    /// 订单类型
    /// </summary>
    public int OrderType { get; set; }
    /// <summary>
    /// 订单优先级
    /// </summary>
    public int? OrderPriority { get; set; }
    /// <summary>
    /// 硫化排
    /// </summary>
    public long DitchId { get; set; }
    /// <summary>
    /// 订单信息
    /// </summary>
    public List<POWmsOutOrderSummary> POWmsOutOrderSummaries { get; set; }
}

public class OutOrderSummary
{
    /// <summary>
    /// 硫化机编号
    /// </summary>
    public string EquipNo { get; set; }
    /// <summary>
    /// 硫化机左右模
    /// </summary>
    public int EquipModel { get; set; }
    /// <summary>
    /// 中间表ID
    /// </summary>
    public string MidId { get; set; }
    /// <summary>
    /// 订单从表ID
    /// </summary>
    public long SummaryId { get; set; }
    /// <summary>
    /// 订单主ID
    /// </summary>
    public long MasterId { get; set; }
    /// <summary>
    /// 作业指示编号
    /// </summary>
    public string Serno { get; set; }
    /// <summary>
    /// 顺序号
    /// </summary>
    public int SummaryIndex { get; set; }
    /// <summary>
    /// 旋转角度
    /// </summary>
    public decimal RotateAngle { get; set; }
    /// <summary>
    /// 目标硫化位
    /// </summary>
    public long TargetLoc { get; set; }
    /// <summary>
    /// 目标设备硫化位
    /// </summary>
    public long TargetId { get; set; }
    /// <summary>
    /// 规格
    /// </summary>
    public string Spec { get; set; }
    /// <summary>
    /// 产品编码
    /// </summary>
    public string MaterialCode { get; set; }
    /// <summary>
    /// 此处批次号 = 产品批次号
    /// </summary>
    public string SkuBatch { get; set; }
    /// <summary>
    /// 是否可以请料（true:可以；false:不可以）
    /// </summary>
    public bool IsCall { get; set; }
    /// <summary>
    /// 实时库存(双模库存：第二条请料库存已经减掉第一条请料库存)
    /// </summary>
    public int Stock { get; set; }
    /// <summary>
    /// 计划数量
    /// </summary>
    public int? PlanCount { get; set; }
    /// <summary>
    /// 起始货位
    /// </summary>
    public long? StartLoc { get; set; }
    public string Remark { get; set; }
}
public class SummaryInCuringCount
{
    /// <summary>
    /// 硫化机位置
    /// </summary>
    public long? LocId { get; set; }
    /// <summary>
    /// 硫化机Id
    /// </summary>
    public long? EquipId { get; set; }
    /// <summary>
    /// 硫化机编号
    /// </summary>
    public string CuringCode { get; set; }
    /// <summary>
    /// 左右模
    /// </summary>
    public string CuringDir { get; set; }
    /// <summary>
    /// 订单数量
    /// </summary>
    public int SummaryCount { get; set; }
    /// <summary>
    /// 如硫化记录数量
    /// </summary>
    public int InCuringCount { get; set; }
}